# 多个文件先进行编译，然后在进行链接

BIN=myproc
OBJ=$(SRC:.c=.o) # 将所有的.c文件生成一分对应的.文件
# SRC=$(wildcard *.c)
SRC=$(shell ls *.c)
CC=gcc
LFLAGS=-o
FLAGS=-c
RM=rm -f

$(BIN):$(OBJ)
	@$(CC) $(LFLAGS) $@ $^
	@echo "linking... $^ to $@"
%.o:%.c
	@$(CC) $(FLAGS) $<
	@echo "compiling... $< to $@"
.PHONY:clean
clean:
	@$(RM) $(OBJ) $(BIN)

# 更好的方式是先将源文件编译为.o，在进行链接
# BIN=myproc
# OBJ=myproc.o
# SRC=myproc.c
# CC=gcc
# LFLAGS=-o
# FLAGS=-c
# RM=rm -f
# 
# $(BIN):$(OBJ)
# 	@$(CC) $(LFLAGS) $@ $^
# 	@echo "linking... $^ to $@"
# $(OBJ):$(SRC)
# 	@$(CC) $(FLAGS) $^
# 	@echo "compiling... $^ to $@"
# 
# .PHONY:clean
# clean:
# 	@$(RM) $(OBJ) $(BIN)


#BIN=myproc
#SRC=myproc.c
#CC=gcc
#FLAGS=-o
#RM=rm -f
#
#$(BIN):$(SRC)
#	$(CC) $(FLAGS) $@ $^
#	# $@指的是目标文件，$^指的是源文件
#	# $(CC) $^ $(FLAGS) $@
#	# @$(CC) $(SRC) $(FLAGS) $(BIN)
#	@echo "linking ... $^ to $@"
#
#.PHONY:clean
#clean:
#	@$(RM) $(BIN)
#
#
#.PHONY:test
#test:
#	@echo $(BIN)
#	@echo $(SRC)
#	@echo $(CC)
#	@echo $(FLAGS)











#myproc:myproc.c
#	gcc myproc.c -o myproc
#.PHONY:clean
#clean:
#	rm -f myproc
